package 测试案例;

import java.util.Arrays;

//测试数组能否逆序
public class Test1 {
    public static void main(String[] args) {
        int[] str = new int[]{1,2,3,4,5,6};

        int[] arr = inverse(str);
        System.out.println(Arrays.toString(str));
        System.out.println(Arrays.toString(arr));

        System.out.println(find(3,arr));

    }
    private static int[] inverse(int[] postorder) {
        int[] arr = new int[postorder.length];
        int n = 0;
        for (int i = postorder.length - 1; i >= 0 ; i--, n++) {
            arr[n] = postorder[i];
        }
        return arr;
    }

    /**
     * 寻找val值在数组中是否存在，返回其索引
     */
    private static int find(int val, int[] inorder) {
        for (int i = 0; i < inorder.length; i++) {
            if(val == inorder[i]){
                return i;
            }
        }
        return -1;
    }

}
